package day11.demo;

/**
 * @Author juzipi
 * @Date 2021/6/28 9:36
 * @Info
 */
public class Account {

    private int id;
    private double balance;//余额
    private double annualInterestRate;//年利率


    public Account(int id, double balance) {
        this.id = id;
        this.balance = balance;
        this.annualInterestRate = getLi(balance);
    }

    private double getLi(double balance) {
        if (balance >= 10000) {
            return 0.32;
        }
        if (balance < 10000) {
            return 0.18;
        }
        return 0;
    }

    //获取月利率
    public double getMonthInterest() {
        return annualInterestRate / 12;
    }

    //取钱
    public void withdraw(double amount) {
        if (balance >= amount) {
            balance -= amount;
            System.out.println("取钱成功!!!");
            return;
        }
        System.out.println("余额不足");
    }

    //存钱
    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
            System.out.println("存钱成功");
        } else {
            System.out.println("存钱失败");
        }
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public double getAnnualInterestRate() {
        return annualInterestRate;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }
}
